package com.haoze.nurse.controller;


import com.haoze.common.response.Result;
import com.haoze.common.response.ResultGenerator;
import com.haoze.nurse.dto.lab.LabSpecimenSearchDto;
import com.haoze.nurse.service.FileIndexService;
import com.haoze.nurse.service.PatientOrderService;
import com.haoze.nurse.vo.Commodel;
import com.haoze.nurse.vo.DoctorAdvicesVO;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/nurse/patientOrder")
public class PatientOrderController {

    @Resource
    PatientOrderService patientOrderService;

    @Resource
    FileIndexService fileIndexService;

    // classId 1:长期，2:临时，9:其他
    // type 1:医嘱开立时间，2:计划开始时间，3:计划结束时间
    @GetMapping("/order")
    @ApiOperation(value = "获取医嘱列表")
    public Result queryOrder(@RequestParam final String inpatNum,
                             @RequestParam(defaultValue = "1") final Integer page,
                             @RequestParam(defaultValue = "20") final Integer size,
                             @RequestParam(defaultValue = "1") final String classId,
                             @RequestParam(defaultValue = "1") final String type,
                             @RequestParam(defaultValue = "1") final String status,
                             @RequestParam(required = false) final String startDate,
                             @RequestParam(required = false) final String endDate) {

        DoctorAdvicesVO doctorAdvicesVO = fileIndexService.queryOrders(inpatNum, classId, type, status, startDate, endDate, page, size);
        return ResultGenerator.genOkResult(doctorAdvicesVO);
    }

    @GetMapping("/orderQRCode")
    @ApiOperation(value = "用药医嘱条码")
    public Result orderQRCode(@RequestParam String inpatNum,@RequestParam String beginTime,@RequestParam String endTime,@RequestParam(required = false) String printType,@RequestParam(required = false) String search) {
        return patientOrderService.orderQRCode(inpatNum,beginTime,endTime,printType,search);
    }

    @GetMapping("/orderQRCodeNew")
    @ApiOperation(value = "用药医嘱条码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inpatNum",value = "病人入院号",dataType = "String",example = "1109812-1",defaultValue = ""),
            @ApiImplicitParam(name = "dateTime",value = "选择日期",dataType = "String",example = "2020-04-21 08:00",defaultValue = ""),
            @ApiImplicitParam(name = "type",value = "是否今日医嘱 0否，1是",dataType = "String",example = "",defaultValue = ""),
            @ApiImplicitParam(name = "printType",value = "打印状态0未打印，1已打印",dataType = "String",example = "0",defaultValue = ""),
            @ApiImplicitParam(name = "administration",value = "用法id",dataType = "String",example = "",defaultValue = ""),
            @ApiImplicitParam(name = "freqTime",value = "频次筛选",dataType = "String",example = "07:00:00",defaultValue = ""),
            @ApiImplicitParam(name = "ordersClass",value = "0 全部 1长期 2临时医嘱",dataType = "String",example = "1长期 2临时",defaultValue = ""),
            @ApiImplicitParam(name = "administrationFilter",value = "用法过滤",dataType = "String",example = "GTT,V",defaultValue = "")
    })
    public Result orderQRCodeNew(@RequestParam String inpatNum,
                                 @RequestParam String dateTime,
                                 @RequestParam String type,
                                 @RequestParam String printType,
                                 @RequestParam String administration,
                                 @RequestParam(required = false) String freqTime,
                                 @RequestParam(required = false) String ordersClass,
                                 @RequestParam(required = false) String administrationFilter,
                                 @RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "20") Integer pageSize) {
        return patientOrderService.orderQRCodeNew(inpatNum, dateTime, type, printType, administration,freqTime,ordersClass,administrationFilter);
    }

    @GetMapping("/staticOrder")
    @ApiOperation(value = "静配医嘱条码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inpatNum",value = "病人入院号",dataType = "String",example = "1109812-1",defaultValue = ""),
            @ApiImplicitParam(name = "beginTime",value = "开始统计时间",dataType = "String",example = "2020-04-21 08:00",defaultValue = ""),
            @ApiImplicitParam(name = "endTime",value = "结束统计时间",dataType = "String",example = "2020-04-21 18:00",defaultValue = ""),
            @ApiImplicitParam(name = "printType",value = "打印状态",dataType = "String",example = "0",defaultValue = ""),
            @ApiImplicitParam(name = "search",value = "模糊查询条件",dataType = "String",example = "束婷",defaultValue = "")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "获取列表完成",response = java.util.Map.class)
    })
    public Result staticOrderList(@RequestParam String inpatNum,@RequestParam String beginTime,@RequestParam String endTime,@RequestParam(required = false) String printType,@RequestParam(required = false) String search){
        return patientOrderService.staticOrderList(inpatNum,beginTime,endTime,printType,search);
    }

    @GetMapping("/printOrderInfo")
    @ApiOperation(value = "查询病人腕带及床头牌")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "printStatus",value = "0:全部1:未打印2补打",dataType = "String",example = "1109812-1",defaultValue = "")
    })
    public Result printOrderInfo(@RequestParam String type,@RequestParam String wardId,@RequestParam String search,@RequestParam(defaultValue = "1") String page,@RequestParam(defaultValue = "20") String pageSize,
                                 @RequestParam String printStatus,@RequestParam(required = false) String printNum){
        return patientOrderService.printOrderInfo(type,wardId,search,page,pageSize,printStatus,printNum);
    }

    @PostMapping("/printPatientInfo")
    @ApiOperation(value = "打印之后记录数据")
    public Result printPatientInfo(@RequestBody Commodel qrCodeMap){
        return patientOrderService.printPatientInfo(qrCodeMap);
    }

    @GetMapping("/staticOrderQRCode")
    @ApiOperation(value = "静配中心二维码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inpatNum",value = "病人入院号",dataType = "String",example = "1109812-1",defaultValue = ""),
            @ApiImplicitParam(name = "beginTime",value = "开始统计时间",dataType = "String",example = "2020-04-21 08:00",defaultValue = ""),
            @ApiImplicitParam(name = "endTime",value = "结束统计时间",dataType = "String",example = "2020-04-21 18:00",defaultValue = ""),
            @ApiImplicitParam(name = "printType",value = "打印状态",dataType = "String",example = "0",defaultValue = ""),
            @ApiImplicitParam(name = "search",value = "模糊查询条件",dataType = "String",example = "束婷",defaultValue = "")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "获取列表完成",response = java.util.Map.class)
    })
    public Result staticOrderQRCode(@RequestParam String inpatNum,@RequestParam String beginTime,@RequestParam String endTime,@RequestParam(required = false) String printType,@RequestParam(required = false) String search) {
        return patientOrderService.staticOrderQRCode(inpatNum, beginTime, endTime, printType, search);
    }

    @GetMapping("/administrationType")
    @ApiOperation(value = "医嘱分类")
    public Result orderType() {
        return patientOrderService.administrationType();
    }

    @GetMapping("/labList")
    @ApiOperation("web端检验标本采集获取检验列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inpatNum",value = "病人入院号",required = true),
            @ApiImplicitParam(name = "beginTime",value = "开始时间",required = false),
            @ApiImplicitParam(name = "endTime",value = "结束时间",required = false),
            @ApiImplicitParam(name = "printType",value = "打印状态 0未打印 1 已打印,默认未打印")
    })
    public Result queryLabList(
            @RequestParam String inpatNum,
            @RequestParam(required = false) String beginTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false,defaultValue = "0") Integer printType
    ){
        LabSpecimenSearchDto labSpecimenSearchDto=new LabSpecimenSearchDto();
        if(StringUtils.isNotBlank(beginTime)){
            beginTime+=" 00:00:00";
        }
        if(StringUtils.isNotBlank(endTime)){
            endTime+= " 23:59:59";
        }
        labSpecimenSearchDto.setBeginTime(beginTime);
        labSpecimenSearchDto.setEndTime(endTime);
        labSpecimenSearchDto.setInpatNum(inpatNum);
        labSpecimenSearchDto.setPrintFlag(printType);
        return ResultGenerator.genOkResult(this.patientOrderService.queryLabSpecimenList(labSpecimenSearchDto));
    }

    @GetMapping("/labSync")
    @ApiOperation("LIS同步条码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wardDeptId",value = "病区id",required = true),
    })
    public Result labSync(@RequestParam String wardDeptId){
        return this.patientOrderService.labSync(wardDeptId);
    }


}